package com.zmn.oms.services.impl.conf.distributereason;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.conf.distributereason.ConfOrderDistributeReason;
import com.zmn.oms.model.entity.conf.distributereason.ConfOrderDistributeReasonQuery;
import com.zmn.oms.persistence.interfaces.conf.distributereason.ConfOrderDistributeReasonDao;
import com.zmn.oms.services.interfaces.conf.distributereason.ConfOrderDistributeReasonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 类描述：改派缘由配置
 *
 * @author liuying
 * @date 2021/10/27 14:27
 */
@Service
public class ConfOrderDistributeReasonServiceImpl implements ConfOrderDistributeReasonService {

    @Resource
    private ConfOrderDistributeReasonDao confOrderDistributeReasonDao;

    @Override
    public List<ConfOrderDistributeReason> listByQuery(ConfOrderDistributeReasonQuery query) {
        List<ConfOrderDistributeReason> confList = confOrderDistributeReasonDao.listByQuery(query);
        return confList;
    }

    @Override
    public List<ConfOrderDistributeReason> listPageByQuery(ConfOrderDistributeReasonQuery query) {
        query.setTotalCount(confOrderDistributeReasonDao.countByQuery(query));
        List<ConfOrderDistributeReason> confList = confOrderDistributeReasonDao.listPageByQuery(query);
        return confList;
    }

    @Override
    public int countByQuery(ConfOrderDistributeReasonQuery query) {
        return confOrderDistributeReasonDao.countByQuery(query);
    }

    @Override
    public ConfOrderDistributeReason findConfById(Integer id) {
        return confOrderDistributeReasonDao.selectByPrimaryKey(id);
    }

    @Override
    public void updateSelectiveById(ConfOrderDistributeReason record) {
        Objects.requireNonNull(record.getId(), "ID不能为空");

        record.setUpdateTime(DateUtil.getNow());
        confOrderDistributeReasonDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateById(ConfOrderDistributeReason record){
        Objects.requireNonNull(record.getId(), "ID不能为空");
        return confOrderDistributeReasonDao.updateByPrimaryKey(record);
    }

    @Override
    public Integer insertConf(ConfOrderDistributeReason record) {
        record.setCreateTime(DateUtil.getNow());
        return confOrderDistributeReasonDao.insertSelective(record);
    }

}
